'use strict';
(function (exports) {
    var $ = null;

    var PhzJieSuan = cc.Layer.extendEX({
        getRootNode: function () {
            return this.getChildByName('Scene');
        },
        ctor: function (isPlayMusic) {
            this._super();
            var that = this;
            that.isPlayMusic = isPlayMusic;
            var file = gameData.playerNum == 3 ? res.PhzJieSuan_json : res.PhzJieSuanFour_json;
            if (gameData.playerNum == 2)
                file = res.PhzJieSuanTwo_json;

            $ = create$(loadNodeCCS(file, this));

            this.close = $('close');
            this.share = $('share');
            this.roomid = $('roomid');
            this.time = $('time');
            this.nCombos = $('nContent.nCombos');
            this.nLaizi = $('nContent.nLaizi');
            this.twin = $('twin');
            // this.kuang2_ly = $("nContent.bg1.kuang2_ly");
            // this.zhx_ly = $("nContent.bg1.kuang1.zhx_ly");
            // this.thx_ly = $("nContent.bg1.kuang1.thx_ly");
            this.n0 = $('nContent.n0');
            this.n1 = $('nContent.n1');
            this.n2 = $('nContent.n2');
            if (gameData.playerNum == 4) {
                this.n3 = $('nContent.n3');
            }
            this.nHu = $('nContent.nHu');
            this.nHuxi = $('nContent.nHuxi');
            this.winBg = $('winbg');
            this.loseBg = $('losebg');

            this.panelResult = $('PanelResult');
            this.panelResult.setVisible(true);
            this.checkResult = $('PanelResult.btn_result_bg.checkResult');
            this.checkResultbg = $('PanelResult.btn_result_bg.checkResultbg');
            this.showTable = $('PanelResult.btn_result_bg.showTable');
            this.showTablebg = $('PanelResult.btn_result_bg.showTablebg');
            this.continue = $('PanelResult.continue');

            TouchUtil.setOnclickListener(this.checkResult, function () {
                // that.showTablebg.setVisible(false);
                // that.checkResultbg.setVisible(true);
                // that.setVisible(true);
                that.removeFromParent();

            });
            TouchUtil.setOnclickListener(this.showTable, function () {
                // that.checkResultbg.setVisible(false);
                // that.showTablebg.setVisible(true);
                that.removeFromParent();
            });
            TouchUtil.setOnclickListener(this.continue, function () {
                if (mRoom.isReplay) {
                    mRoom.isReplay = false;
                    clearInterval(mRoom.interval);
                    gameData.roomId = 0;
                    gameData.wanfatype = '';
                    //cc.eventManager.removeAllListeners();
                    showBoard('HallBoard');
                } else {
                    // that.removeFromParent();
                    that.room.showRoomClean();
                    //that.room.showReadyJiesuan(true);
                    that.room.onReady(true);
                    that.removeFromParent();
                }
            });

            TouchUtil.setOnclickListener(this.close, function () {
                if (mRoom.isReplay) {
                    mRoom.isReplay = false;
                    clearInterval(mRoom.interval);
                    gameData.roomId = 0;
                    //cc.eventManager.removeAllListeners();
                    gameData.wanfatype = '';
                    showBoard('HallBoard');
                } else {
                    // that.removeFromParent();
                    that.room.showRoomClean();
                    //that.room.showReadyJiesuan(true);
                    that.room.onReady(true);
                    that.removeFromParent();
                }
            });
            TouchUtil.setOnclickListener(this.share, function () {
                if (!cc.sys.isNative)
                    return;
                // if (getNativeVersion() > '2.0.1') {
                //     that.addChild(new ShareTypeLayer(that));
                // } else {
                //     WXUtils.captureAndShareToWX(that);
                // }

            });

            return true;
        },
        setRoom: function (room, huInfo, gameOverData, isReplay) {
            this.room = room;
            this.huInfo = huInfo;
            this.gameOverData = gameOverData;
            this.isReplay = isReplay;
            // console.log(huInfo);
            // console.log(this.gameOverData);

            this.time.setString(this.gameOverData.EndTime);
            this.roomid.setString('房号:' + gameData.roomId + ' 局数:' + mRoom.getRound(mRoom.curRound));

            //判断上家  下家  胜
            var myturn = 0, winnerturn = 0;
            var users = this.gameOverData.Users;
            for (var i = 0; i < users.length; i++) {
                var userId = users[i].UserID;
                if (userId == gameData.uid) {
                    myturn = i + 1;
                } else if (userId == this.gameOverData.Winner) {
                    winnerturn = i + 1;
                }
            }
            this.setData(myturn, winnerturn);
        },

        setData: function (myturn, winnerturn) {
            this.index = 0;

            var titleImg = '';
            var isHuang = false;
            var that = this;
            if (that.isPlayMusic) {
                playEffect('getw');
            }

            if (this.huInfo != null) {
                this.winCards = [];
                var comListArray = [];
                if (this.huInfo.openList) {
                    for (var i = 0; i < this.huInfo.openList.length; i++) {
                        comListArray.push(this.huInfo.openList[i]);
                    }
                }
                if (this.huInfo.kanList) {
                    for (var i = 0; i < this.huInfo.kanList.length; i++) {
                        comListArray.push(this.huInfo.kanList[i]);
                    }
                }
                if (this.huInfo.huList) {
                    if (mRoom.wanfatype == mRoom.WEIMAQUE) {
                        for (var s = 0; s < this.huInfo.huList.length; s++) {
                            //偎麻雀
                            var onelist = this.huInfo.huList[s];
                            if (onelist.typ == 12 && onelist.cards.length > 4) {
                                var t = {typ: 12};
                                t.cards = [];
                                for (var i = 0; i < onelist.cards.length; i++) {
                                    if (onelist.cards[i]) {
                                        t['cards'].push(onelist.cards[i]);
                                        if (t.cards.length == 3 || i == onelist.cards.length - 1) {
                                            comListArray.push(t);
                                            t = {typ: 12};
                                            t['cards'] = [];
                                        }
                                    }
                                }
                            } else {
                                comListArray.push(onelist);
                            }
                        }
                    } else {
                        for (var i = 0; i < this.huInfo.huList.length; i++) {
                            comListArray.push(this.huInfo.huList[i]);
                        }
                    }
                }
                this.addComboList(comListArray);
                //扯胡子  癞子   祁阳落地扫 衡阳十胡卡
                if ((mRoom.wanfatype == mRoom.CHEHUZI || mRoom.wanfatype == mRoom.QIYANG
                    || mRoom.wanfatype == mRoom.QIYANG3 || mRoom.wanfatype == mRoom.HENGYANG || mRoom.wanfatype == mRoom.SHIHUKA)
                    && this.gameOverData.XingCard) {
                    //番醒
                    var lineNum = 0;
                    var fanxing = $('fanxing', this.nLaizi);
                    //var showfan = "翻醒";
                    if (mRoom.Fanxing == 'gen')
                        fanxing.setTexture(huzi.resPath+'dynamicRes/' + 'result/genxing.png');
                    else
                        fanxing.setTexture(huzi.resPath+'dynamicRes/' + 'result/fanxing.png');

                    var fanxingnum = $('fanxingnum', this.nLaizi);
                    var card = $('fanxingcard', this.nLaizi);
                    var cardsrc = PhzLayer.getCardImg('small_' + this.gameOverData.XingCard);
                    setUIImageFrameByName(card, cardsrc, 'card_common');
                    //fanxing.setString(showfan);
                    fanxingnum.setString('+' + this.gameOverData.XingCount);
                    if (this.gameOverData.XingCard == 0) {
                        fanxing.setVisible(false);
                        card.setVisible(false);
                        fanxingnum.setVisible(false);
                    } else {
                        lineNum++;
                        fanxing.setVisible(true);
                        card.setVisible(true);
                        fanxingnum.setVisible(true);
                    }
                    //癞子
                    var laiziArr = [];
                    for (var i = 0; i < comListArray.length; i++) {
                        var onelist = comListArray[i];
                        for (var j = 0; j < onelist.cards.length; j++) {
                            if (onelist.cards[j] >= 100 && onelist.cards[j] < 200) {
                                laiziArr.push(onelist.cards[j]);
                                lineNum++;
                            }
                        }
                    }
                    var huTypeNum = 0;
                    //名堂
                    for (var i = 0; i < 20; i++) {
                        var isOk = mAction.checkOpen(this.gameOverData.FanFlag, 1 << i);
                        if (isOk) {
                            huTypeNum++;
                            lineNum++;
                        }
                    }
                    //设置scrollview;
                    var scrollInnerHeight = 280;
                    if (50 * lineNum > 280) {
                        scrollInnerHeight = 50 * lineNum;
                        this.nLaizi.setInnerContainerSize(cc.size(300, scrollInnerHeight));
                    }

                    this.setHuInfo(this.gameOverData.FanFlag, this.gameOverData.FanFlag2);

                    fanxing.setPositionY(scrollInnerHeight - 20 - (huTypeNum * 0) * 50);
                    fanxingnum.setPositionY(scrollInnerHeight - 20 - (huTypeNum * 0) * 50);
                    card.setPositionY(scrollInnerHeight - 20 - (huTypeNum * 0) * 50);

                    this.laiziArr = laiziArr;
                    var laizi1 = $('laizi1', this.nLaizi);
                    var flash = $('flash', this.nLaizi);
                    var laizito1 = $('laizito1', this.nLaizi);
                    if (laiziArr.length > 0) {
                        laizi1.setVisible(true);
                        flash.setVisible(true);
                        laizito1.setVisible(true);
                        for (var i = 0; i < laiziArr.length; i++) {
                            if (i != 0) {
                                laizi1 = duplicateSprite(laizi1);
                                flash = duplicateSprite(flash);
                                laizito1 = duplicateSprite(laizito1);
                                this.nLaizi.addChild(laizi1);
                                this.nLaizi.addChild(flash);
                                this.nLaizi.addChild(laizito1);
                            }
                            laizi1.setPositionY(scrollInnerHeight - (i + 1.5) * 50 - (huTypeNum) * 50);
                            flash.setPositionY(scrollInnerHeight - (i + 1.5) * 50 - (huTypeNum) * 50);
                            laizito1.setPositionY(scrollInnerHeight - (i + 1.5) * 50 - (huTypeNum) * 50);
                            // var cardsrc = PhzLayer.getCardImg('small_' + 21 + '.png');
                            // setUIImageFrameByName(laizi1, cardsrc, 'card_common');
                            laizi1.loadTexture(huzi.resPath+'dynamicRes/' + 'small_21.png', ccui.Widget.LOCAL_TEXTURE);
                            var cardsrc = PhzLayer.getCardImg('small_' + (laiziArr[i] - 100));
                            setUIImageFrameByName(laizito1, cardsrc, 'card_common');
                        }
                    } else {
                        laizi1.setVisible(false);
                        flash.setVisible(false);
                        laizito1.setVisible(false);
                    }
                }

                if (this.winCards && this.winCards.length > 0) {
                    for (var s = this.winCards.length - 1; s >= 0; s--) {
                        var card = this.winCards[s];
                        if (this.gameOverData.ByCard && this.gameOverData.ByCard == card.data) {
                            var huicon = new cc.Sprite(huzi.resPath+'dynamicRes/' + 'back.png');
                            huicon.setAnchorPoint(cc.p(0.5, 0.5));
                            huicon.setPosition(cc.p(card.getContentSize().width / 2, card.getContentSize().height / 2));
                            huicon.setOpacity(160);
                            huicon.setScale(1.1);
                            card.addChild(huicon, 2);
                            break;
                        }
                    }
                }
                if (this.gameOverData.Winner == gameData.uid) {
                    titleImg = 'twin.png';
                    this.winBg.setVisible(true);
                    this.loseBg.setVisible(false);
                } else {
                    this.winBg.setVisible(false);
                    this.loseBg.setVisible(true);
                    titleImg = 'tlose.png';
                    if (mRoom.wanfatype == mRoom.HENGYANG) {
                        if (myturn + 1 == winnerturn || (myturn == 4 && winnerturn == 1)) {
                            titleImg = 'txiajiawin.png';
                        }
                        if (myturn == winnerturn + 1 || (myturn == 1 && winnerturn == 4)) {
                            titleImg = 'tshangjiawin.png';
                        }
                        if (myturn == winnerturn + 2 || myturn + 2 == winnerturn) {
                            titleImg = 'tduijiawin.png';
                        }
                    } else {
                        if (myturn + 1 == winnerturn || (myturn == 3 && winnerturn == 1)) {
                            titleImg = 'txiajiawin.png';
                        }
                        if (myturn == winnerturn + 1 || (myturn == 1 && winnerturn == 3)) {
                            titleImg = 'tshangjiawin.png';
                        }
                    }
                }
            } else {
                this.winBg.setVisible(false);
                this.loseBg.setVisible(true);
                titleImg = 'thuang.png';
                isHuang = true;
            }

            this.twin.setTexture(huzi.resPath+'dynamicRes/' + 'result/' + titleImg);

            // if(mRoom.getPlayerNum() == 3){
            //     for(var i=0;i<3;i++){
            //         var n = this["n" + i];
            //         n.setPositionY(500 - i*190);
            //     }
            //     this.n3.setVisible(false);
            // }
            for (var i = 0; i < this.gameOverData.Users.length; i++) {
                var gr = this.gameOverData.Users[i];
                this.setPlayerInfo(i + 1, gr, this.gameOverData.Winner, isHuang);
            }

            if (mRoom.wanfatype == mRoom.LEIYANG) {
                //耒阳
                // this.kuang2_ly.setVisible(true);
                // this.zhx_ly.setVisible(true);
                // this.thx_ly.setVisible(true);
                // this.zhx_ly.setString(this.gameOverData.WinnerXi);
                // for (var i = 0; i < this.gameOverData.Users.length; i++) {
                //     var gr = this.gameOverData.Users[i];
                //     var pos = mRoom.getUserPosIndex(gr.UserID);
                //     var name = $("name_" + (pos), this.kuang2_ly);
                //     var scoreS = $("score_" + (pos), this.kuang2_ly);
                //     var scoreB = $("score_b" + (pos), this.kuang2_ly);
                //     name.setString(ellipsisStr(decodeURIComponent(gr.UserName), 6));
                //     scoreS.setString(gr.SmallTiLong || 0);
                //     scoreB.setString(gr.BigTiLong || 0);
                // }
                // for (var i = 0; i < 3; i++) {
                //     var n = this["n" + i];
                //     var t = $("t" + i, n);
                //     t.setString("得分:");
                // }

                var t1 = $('t1', this.nHuxi);
                var t2 = $('t2', this.nHuxi);
                var t3 = $('t3', this.nHuxi);
                var txt1 = $('txt1', this.nHuxi);
                var txt2 = $('txt2', this.nHuxi);
                var txt3 = $('txt3', this.nHuxi);
                var txt4 = $('txt4', this.nHuxi);

                txt2.setString(this.gameOverData.WinnerFan);
                txt3.setString(this.gameOverData.WinnerXi);
                txt4.setString(this.gameOverData.WinnerJi);
                if (this.gameOverData.WinnerFan == 0) {
                    txt1.setString(this.gameOverData.WinnerXi);
                } else {
                    txt1.setString(this.gameOverData.WinnerXi / this.gameOverData.WinnerFan);
                }

            } else if (mRoom.wanfatype == mRoom.HENGYANG) {
                var t1 = $('t1', this.nHuxi);
                var t2 = $('t2', this.nHuxi);
                var t3 = $('t3', this.nHuxi);
                var txt1 = $('txt1', this.nHuxi);
                var txt2 = $('txt2', this.nHuxi);
                var txt3 = $('txt3', this.nHuxi);
                var txt4 = $('txt4', this.nHuxi);

                txt1.setString(this.gameOverData.WinnerTun);
                txt2.setString(this.gameOverData.WinnerFan);
                txt3.setString(this.gameOverData.WinnerXi);
                txt4.setString(this.gameOverData.WinnerJi);

                // if(this.gameOverData.WinnerFan == 0){
                //     txt1.setString(this.gameOverData.WinnerJi);
                // } else {
                //     txt1.setString(this.gameOverData.WinnerJi / this.gameOverData.WinnerFan);
                // }

            } else if (mRoom.wanfatype == mRoom.SHIHUKA) {
                var t1 = $('t1', this.nHuxi);
                var t2 = $('t2', this.nHuxi);
                var t3 = $('t3', this.nHuxi);
                var t4 = $('t4', this.nHuxi);
                var txt1 = $('txt1', this.nHuxi);
                var txt2 = $('txt2', this.nHuxi);
                var txt3 = $('txt3', this.nHuxi);
                var txt4 = $('txt4', this.nHuxi);

                txt1.setString(this.gameOverData.WinnerXi);
                txt2.setString(this.gameOverData.WinnerFan);
                txt3.setVisible(false);
                t3.setVisible(false);
                txt4.setString(this.gameOverData.WinnerJi);
                txt4.setPosition(txt3.getPosition());
                t4.setPosition(t3.getPosition());


            }
            this.setHuInfo(this.gameOverData.FanFlag, this.gameOverData.FanFlag2);
            // var kuang3 = $('nContent.bg1.kuang3');
            // kuang3.setVisible(true);
            // for(var i=0;i<this.gameOverData.LeftCards.length;i++){
            //     var card = new Card();
            //     kuang3.addChild(card);
            //     card.setData(this.gameOverData.LeftCards[i], null, 2);
            //     card.setPosition(cc.p(30 + 44 * (i%12), 80 - 50*(Math.floor(i/12))));
            // }
            var _cardlen = this.gameOverData.LeftCards.length;
            var _dipaiY = $('nContent.ndipai.dipai').getPositionY();
            for (var i = 0; i < this.gameOverData.LeftCards.length; i++) {
                $('nContent.ndipai.dipai').setPositionX(1280 / 2 - (44 * this.gameOverData.LeftCards.length) / 2 - 50);
                var card = new Card();
                card.setData(this.gameOverData.LeftCards[i], null, 2);
                $('nContent.ndipai').addChild(card);
                card.setPosition(cc.p(1280 / 2 - (this.gameOverData.LeftCards.length / 2 - i) * 44 + 22,
                    $('nContent.ndipai.dipai').getPositionY()));
                //当剩余排数大于20时处理
                if (_cardlen > 20) {
                    if (i < 20) {
                        card.setPositionX(1280 / 2 - (10 - i) * 44 + 22);
                        card.setPositionY(_dipaiY + 29);
                    } else {
                        card.setPositionX(1280 / 2 - (30 - i) * 44 + 22);
                        card.setPositionY(_dipaiY - 20);
                    }
                }
            }
            if (_cardlen > 20) {
                $('nContent.ndipai.dipai').setPositionX(1280 / 2 - (44 * 20) / 2 - 50);
            }
        },

        setPlayerInfo: function (index, gr, winner, isHuang) {
            var pos = mRoom.getUserPosIndex(gr.UserID);
            var n = this['n' + pos];
            var txtUserName = $('txtUserName', n);
            var txtUserId = $('txtUserId', n);
            var txtScore = $('txtScore', n);
            var dianpao = $('dianpao', n);
            var t = $('ti', n);
            var zhuang = $('zhuang', n);

            if (mRoom.wanfatype == mRoom.GUILIN) {
                t.setString('总舵数:');
            }
            //点炮
            // console.log(this.gameOverData);
            if (this.gameOverData.ByWho && this.gameOverData.ByWho != null && this.gameOverData.ByWho == gr.UserID) {
                dianpao.setVisible(true);
            } else {
                if (dianpao)
                    dianpao.setVisible(false);
            }
            //赢家
            if (this.gameOverData.Winner && this.gameOverData.Winner != null && this.gameOverData.Winner == gr.UserID) {
                dianpao.setVisible(true);
                dianpao.setTexture(huzi.resPath+'dynamicRes/' + 'roomclean/hu.png');
            }
            //头像
            var avatorbg = $('head', n);
            var avator = avatorbg.getChildByName('avator');
            if (avator == null) {
                avator = new cc.Sprite(huzi.res.transparent_97x99_png);
                avator.setPosition(avatorbg.getContentSize().width / 2, avatorbg.getContentSize().height / 2);
                avator.setScale(0.9);
                avator.setName('avator');
                avatorbg.addChild(avator, -1);
            }
            var url = (mRoom.getUserByUserId(gr.UserID) == null ? null : mRoom.getUserByUserId(gr.UserID).HeadIMGURL);
            url = decodeURIComponent(url);
            if (url == undefined || (url.length == 0)) url = 'res/defaultHead.jpg';
            var asize = avator.getContentSize();
            cc.log('asize.width = ' + asize.width);
            cc.log('asize.height = ' + asize.height);
            loadImageToSprite(url, avator);//头像

            txtUserName.setString(ellipsisStr(decodeURIComponent(gr.UserName), 6));
            txtUserId.setString('ID:' + gr.UserID);
            if (gr.Result) {
                if (gr.Result > 0)
                    txtScore.setString('得分:' + '+' + gr.Result);
                else
                    txtScore.setString('得分:' + gr.Result);
            } else {
                txtScore.setString('得分:' + '0');
            }
            var score = mRoom.scoreInfo[gr.UserID] || 0;
            // mRoom.scoreInfo[gr.UserID] = score + gr.Result + 0;
            mRoom.scoreInfo[gr.UserID] = gr.Score;

            var win = $('win', n);
            if (gr.Result > 0) {
                win.setTexture(huzi.resPath+'dynamicRes/' + 'result/win.png');
            } else if (gr.Result == 0) {
                win.setTexture(huzi.resPath+'dynamicRes/' + 'result/ping.png');
            } else {
                win.setTexture(huzi.resPath+'dynamicRes/' + 'result/lose.png');
            }
            //显示庄
            if (gr.UserID == this.gameOverData.Banker) {
                zhuang.setVisible(true);
            }
            //显示得分
            this.room.updateScore(pos);
            if (gr.SmallTiLong || gr.BigTiLong) {
                t.setString('提龙:' + (gr.SmallTiLong || 0) + '小/' + (gr.BigTiLong || 0) + '大');
            } else {
                t.setVisible(false);
            }

        },

        setHuInfo: function (flag, flag2) {
            var index = 0;
            var imgs = ['h_hong2', 'h_hei2', 'h_zimo', 'h_tian2', 'h_di2', 'h_yidian', 'h_hw', 'h_ddh', 'h_wudh'];
            var fans = ['', '', '', '', '', '', '', '', ''];

            if (mRoom.isallmt == true) {  //全名堂
                var info = mCard.getHuCardCountInfo(this.huInfo);
                var big = info.big;
                var small = info.small;
                var red = info.red;

                imgs = ['h_hong2', 'h_zdh', 'h_jdh', 'h_hw', 'h_wh', 'h_ddh', 'h_big', 'h_small',
                    'h_hdh', 'h_zimo', 'h_tian2', 'h_di2', 'h_myjh'];
                //海底胡	玩家所胡的牌是墩中最后的一只牌（平胡加1番，名堂胡加2番）
                var isPingHu = true;
                for (var i = 0; i < imgs.length; i++) {
                    var isOk = mAction.checkOpen(flag, 1 << i);
                    if (isOk && i < 8) {
                        isPingHu = false;
                        break;
                    }
                }
                var hdx_fan = 2;

                fans = ['', '', '', '', '', '', '', '', '', '', '', '', ''];
            }
            if (mRoom.wanfatype == mRoom.FANGPAOFA) {
                // 一点红 0x1 1
                // 自摸 0x2  2
                // 一块匾 0x4  4
                // 乌胡 0x8  8
                // 海底胡 0x10   16
                // 红胡 0x20   32
                // 卡胡 0x40   64
                // 天胡 0x80    128
                // 地胡 0x100   256
                // 10红 0x200 10红  512
                imgs = ['h_yidian', 'h_zimo', 'h_bian', 'h_wh', 'h_hdh', 'h_hong2',
                    'h_ka', 'h_tian2', 'h_di2', 'h_shi'];
                fans = ['', '', '', '', '', '', '', '', '', ''];
            }
            //天地红黑  无全名堂
            if (mRoom.subWanfa != undefined && (mRoom.subWanfa == 'tiandihonghei' || mRoom.subWanfa == 'wumingtang')) {
                imgs = ['h_hong2', 'h_hei2', 'h_zimo', 'h_tian2', 'h_di2'];
                // fans = [2, 2, 1, 2, 2];
                fans = ['', '', '', '', ''];
            }
            if (mRoom.wanfatype == mRoom.LEIYANG) {
                // 1		2		4		8 		16		32     64   128     256
                // 红胡		黑胡		无胡		卡胡		天胡		举手   自摸   一点红  地胡
                imgs = ['h_hong2', 'h_hei2', 'h_wuh', 'h_ka', 'h_tian2', 'h_jz', 'h_zimo', 'h_yidian', 'h_di2'];
                fans = ['', '', '', '', '', '', '', ''];
            }
            if (mRoom.wanfatype == mRoom.CHANGSHA) {
                // 红胡		点胡		红乌		黑胡		天胡		地胡		对对胡		大胡		小胡
                // 1		2		4		8		16		32		64			128		256
                // 十红		一点红	十八小	十八大	二比		三比		四比		双飘		海底胡  自摸
                // 512		1024	2048	4096	8192	16384	32768	65536	131072  262144
                imgs = ['h_hong2', 'h_dianh', 'h_wh', 'h_hei2', 'h_tian2', 'h_di2', 'h_ddh', 'h_dah', 'h_xiaoh',
                    'h_shi', 'h_yidian', 'h_small', 'h_big', 'h_ebh', 'h_sbh', 'h_sibh', 'h_sph', 'h_hdh', 'h_zimo'];
                fans = ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''];
            }
            if (mRoom.wanfatype == mRoom.SHAOYANG) {
                imgs = ['h_hong2', 'h_hei2', 'h_tian2', 'h_di2'];
                fans = ['', '', '', ''];
            }
            if (mRoom.wanfatype == mRoom.SHAOYANGBOPI) {
                //天胡 地胡 自摸 中庄
                imgs = ['h_tian2', 'h_di2', 'h_zimo', 'h_zhh'];
                fans = ['+10', '+10', '+10', ''];
            }
            if (mRoom.wanfatype == mRoom.HONGGUAIWAN) {
                //天湖	地胡		点胡		红胡		乌胡		碰碰胡		十八大		十六小		海底胡	自摸
                //1		2		4		8		16		 32			64			128			256		512
                imgs = ['h_tian2', 'h_di2', 'h_dianh', 'h_hong2', 'h_wh', 'h_pph', 'h_big', 'h_small', 'h_hdh', 'h_zimo'];
                fans = ['', '', '', '', '', '', '', '', '', ''];
            }
            if (mRoom.wanfatype == mRoom.XIANGXIANG) {
                // 自摸	黑胡	红乌	红胡	 30胡	30红 	天胡 	地胡
                // 1	2	4	8	 16	     32	    64	    128
                imgs = ['h_zimo', 'h_hei2', 'h_wh', 'h_hong2', 'h_30huh', 'h_30hongh', 'h_tian2', 'h_di2'];
                fans = ['', '', '', '', '', '', '', ''];
            }
            if (mRoom.wanfatype == mRoom.YOUXIAN) {
                //天胡  地胡  中庄 跑双 双龙 7对 五福  "" ""  "" 连中(X1)
                // 1     2    4    8  16   32  64 128 256 512 1024 2048
                imgs = ['h_tian2', 'h_di2', 'h_zhh', 'h_psh', 'h_slh', 'h_qdh', 'h_wfh', '', '', '',
                    'h_lzh2', 'h_lzh3', 'h_lzh4', 'h_lzh5', 'h_lzh6', 'h_lzh7', 'h_lzh8', 'h_lzh9', 'h_lzh10'];
                fans = ['', '', '', '', '', '', '', '', '', '',
                    '', '', '', '', '', '', '', '', ''];
            }
            if (mRoom.wanfatype == mRoom.GUILIN) {
                //天胡  地胡  自摸
                // 1     2    4    8
                imgs = ['h_tian2', 'h_di2', 'h_zimo', ''];
                fans = ['', '', '', ''];
            }
            if (mRoom.wanfatype == mRoom.CHENZHOU || mRoom.wanfatype == mRoom.MAOHUZI) {
                //天胡 自摸  红胡 黑胡 毛胡
                //1     2    4    8   16
                imgs = ['h_tian2', 'h_zimo', 'h_hong2', 'h_hei2', 'h_maoh'];
                fans = ['', '', '', '', ''];
            }
            if (mRoom.wanfatype == mRoom.HENGYANG) {
                //自摸，大红，小红，一点红，黑胡
                //1 ，  2，   4，    8，   16
                imgs = ['h_zimo_hy', 'h_dahong', 'h_xiaohong', 'h_yidian', 'h_hei2'];
                fans = ['', '', '', '', ''];
            }
            if (mRoom.wanfatype == mRoom.SHIHUKA) {
                //自摸，天胡，地胡，一点红，小红，大红 ，黑胡，海底胡
                //1     2    4     8     16   32   64     128
                imgs = ['h_zimo', 'h_tian2', 'h_di2', 'h_yidian', 'h_xiaohong', 'h_dahong', 'h_hei2'];
                fans = ['', '', '', '', '', ''];
            }
            if (mRoom.subWanfa == 'bashifan') {
                //     自摸 红胡 真点胡  乌胡  对对胡  大 小  听胡  天胡  地胡  耍猴  海底  大团圆  行行息  背靠背  魅一级
                //1 ，  2，  4，   8，   16    32   64 128 256   512  1024 2048 4096 8192   16384   32768  65536
                //多黄单番 一黄一番  两黄两番  三黄三番  多黄多番
                //131072   261072
                imgs = ['', 'h_zimo', 'h_hong2', 'h_zdh', 'h_wh', 'h_ddh', 'h_dah', 'h_xiaoh', 'h_th',
                    'h_tian2', 'h_di2', 'h_sh', 'h_hdh', 'h_dty', 'h_xxx', 'h_bkb', 'h_myjh',
                    'h_dhdf', 'h_yhyf', 'h_lhlf', 'h_shsf', 'h_dhdf2'];
                fans = ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''];
            }
            if (mRoom.wanfatype == mRoom.HENGDONG) {
                //自摸，天胡，地胡，红胡，黑胡，小胡 碰碰胡，
                //1     2    4     8    16   32 64
                imgs = ['h_zimo', 'h_tian2', 'h_di2', 'h_hong2', 'h_hei2', 'h_xiaoh', 'h_pph'];
                fans = ['', '', '', '', '', ''];
            }

            var imgs2 = [];
            if (mRoom.wanfatype == mRoom.WEIMAQUE) {
                //大小卓通用：
                //自摸： 0x1 红胡：0x2 多红：0x4 对子胡：0x8 乌对：0x10 乌胡：0x20 点胡：0x40 满园花：0x80 大字胡：0x100 小字胡：0x200
                //海底胡：0x400 单吊：0x800 卡偎：0x1000 天胡:0x2000 地胡：0x4000 全求人：0x8000 项对：0x10000 飘对：0x20000 鸡丁:0x40000 上下五千年:0x80000
                imgs = ['h_zimo', 'h_hong2', 'h_dred', 'h_dzhu', 'h_wdui', 'h_wh', 'h_dianh', 'h_myhua', 'h_dazi', 'h_xiaozihu',
                    'h_hdh', 'h_dand', 'h_kw', 'h_tian2', 'h_di2', 'h_qqr', 'h_xdui', 'h_piaod', 'h_jd', 'h_sxwqn'];
                //印胡 0x1  纯印 0x2  卓胡 0x4  姊妹卓 0x8  三乱卓 0x10  姊妹卓带拖 0x20  祖孙卓 0x40  四乱卓 0x80  祖孙卓带拖 0x100  八碰头 0x200
                //假八碰头 0x400  背靠背 0x800  手牵手 0x1000  龙摆尾 0x2000
                //全黑  0x4000 无息 0x8000 六队红 0x10000 九队 0x20000 四边对 0x40000 边坎 0x80000 真背靠背 0x10000 凤摆尾 0x200000 卡胡 0x400000
                imgs2 = ['h_yinh', 'h_chunyin', 'h_zhuoh', 'h_zmz', 'h_sanlz', 'h_zmzdt', 'h_zsz', 'h_szll', 'h_zszdt', 'h_bapengtou',
                    'h_jbpt', 'h_bkb', 'h_sqs', 'h_lbw',
                    'h_quanhei', 'h_wuxi', 'h_liuduihong', 'h_jiudui', 'h_sibiandui', 'h_biankan', 'h_beikaobei', 'h_fengbaiwei', 'h_ka'];

            }

            var _type = '';
            if (gameData.wanfatype == mRoom.LEIYANG) {
                _type = 'leiyang/';
            }

            for (var i = 0; i < imgs.length; i++) {
                var isOk = mAction.checkOpen(flag, 1 << i);
                if (isOk && imgs[i] != '') {
                    var spr = new cc.Sprite(huzi.resPath+'dynamicRes/' + 'result/' + _type + imgs[i] + '.png');
                    spr.setAnchorPoint(0, 0.5);
                    this.nLaizi.addChild(spr);
                    //spr.setPosition(0, -40 - index * 50);
                    spr.setPosition(28, this.nLaizi.innerHeight - (index + 2.5) * 50);
                    //spr.setPosition(28, this.nLaizi.innerHeight - (index + .5)*50);
                    index++;
                }
            }
            for (var i = 0; i < imgs2.length; i++) {
                var isOk2 = mAction.checkOpen(flag2, 1 << i);
                if (isOk2 && imgs2[i] != '') {
                    var spr = new cc.Sprite('res/paohuz/result/' + imgs2[i] + '.png');
                    spr.setAnchorPoint(0, 0.5);
                    this.nLaizi.addChild(spr);
                    spr.setPosition(28, this.nLaizi.innerHeight - (index + 2.5) * 50);
                    index++;
                }
            }
        },
        addComboList: function (comboList) {
            var hasDui = null;
            for (var i = 0; i < comboList.length; i++) {
                var comboInfo = comboList[i];
                if (comboInfo.typ != mCard.comboTypes.dui) {
                    var ci = new ComboInfo();
                    this.nCombos.addChild(ci);
                    ci.setData(comboInfo, comboList);
                    ci.setPosition(10 + this.index * 60, 5);
                    this.index++;

                    var cardSprite = ci.getCardSprite();
                    for (var s = 0; s < cardSprite.length; s++) {
                        this.winCards[this.winCards.length] = cardSprite[s];
                    }
                } else {
                    hasDui = comboInfo;
                }
            }
            if (hasDui != null) {
                var ci = new ComboInfo();
                this.nCombos.addChild(ci);
                ci.setData(hasDui, comboList);
                ci.setPosition(10 + this.index * 60, 5);

                var cardSprite = ci.getCardSprite();
                for (var s = 0; s < cardSprite.length; s++) {
                    this.winCards[this.winCards.length] = cardSprite[s];
                }
            }
        }
    });
    exports.PhzJieSuan = PhzJieSuan;
})(window);